package com.liang.auth.api.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public static Result<Void> ok() {
        return ok(null);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(true, ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getDesc(), data);
//        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getDesc(), data);
    }

    public static <T> Result<T> ok(String message) {
        return new Result<>(true, ResultCodeEnum.SUCCESS.getCode(), message, null);
    }

    public static <T> Result<T> ok(T data, String message) {
        return new Result<>(true, ResultCodeEnum.SUCCESS.getCode(), message, data);
    }

    public static Result fail(String message) {
        return new Result<>(false, ResultCodeEnum.FAIL.getCode(), message, null);
//        return new Result<>(ResultCodeEnum.FAIL.getCode(), message, null);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<>(false, ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc(), data);
//        return new Result<>(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc(), data);
    }

    public static <T> Result<T> fail(T data, String message) {
        return new Result<>(false, ResultCodeEnum.FAIL.getCode(), message, data);
//        return new Result<>(ResultCodeEnum.FAIL.getCode(), message, data);
    }
}
